<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- 微软的老式浏览器 -->
    <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <!-- 显示窗口 宽度 是 客户端的 屏幕 宽度 （就是 满屏 ！），显示的文字和图形的初始比例 是 1.0 -->
    <link rel="stylesheet" type="text/css" href="css/style.css">
    <script src="js/common.js"></script>
    <script src="js/jquery/rem.min.js"></script>
	<title>反馈界面</title>
</head>
<body>
	<div class="feedback">
		  <textarea cols="50" rows="15" id="textarea" placeholder="请把您使用中的意见告诉我们"></textarea>
	</div>
    <div class="pptv">
    <div class="popo">
        <div class="img-list">
            <div id="imglist">
                <!--<div class="img pr" style="background-image: url(http://cpfile.oss-cn-beijing.aliyuncs.com/portrait_pic/liuyifei1.jpg)">-->
                <!--<a href="javascript:;" class="pa" onclick="del(this)"></a>-->
                <!--</div>-->
            </div>
            <div class="addhao" id="upload-btn">
            </div>
        </div>

        <input style="display: none" type="file" id="file" accept="image/png,image/gif,image/jpeg,image/jpg">
    </div>
    </div>
	<div class="didi">
		<input type="button" value="提交意见" onclick="submit()">
	</div>

    <script src="js/jquery/jquery-2.2.4.min.js"></script>
    <script src="js/jquery/upload.js"></script>
    <script src="js/jquery/layer.js"></script>
    <script src="js/utils.js"></script>
    <script>
        Utils.historyBack(function () {
            window.location.href = '/mine.html';
        });
    var imgarr=[];
    $(function () {
        $("#xtbtn").on('click',function () {
            $("#xtxx").slideToggle(500)
        });
        new Upload({
            button :"#upload-btn",
            file : '#file',
            module : 'album',
            success : function (url) {
                $("#imglist").html("");
                imgarr.push(url);
                console.log(imgarr.toString());
                 var strs="";
                 $.each(imgarr,function (i,el) {
                     strs+=`<div class="img pr" style="background-image: url(`+el+`)">
						 <a href="javascript:;" class="pa" data-id=`+i+` onclick="del(this)"></a>
					 </div>`
                 });
                 $(strs).appendTo("#imglist");
                 if(imgarr.length==4){
                     $("#upload-btn").hide();
                 }
            },
            error : function (data) {
                alert('网络错误');
            }
        });
    });

    function del(obj) {
        var $this=$(obj);
        var index=$this.attr("data-id");
        imgarr.splice(index,1);
        $this.parent().remove();
//        $("#imglist").html("");
//         var strs="";
//         $.each(imgarr,function (i,el) {
//             strs+=`<div class="img pr" style="background-image: url(`+el+`)">
//						 <a href="javascript:;" class="pa" data-id=`+i+` onclick="del(this)"></a>
//					 </div>`
//         });
//         $(strs).appendTo("#imglist");
        $("#upload-btn").show();
        console.log(imgarr.toString())
    }
    function submit() {
        //user/add_feedback
        console.log(imgarr);
        if($("#textarea").val()==""){
            layer.open({
                content:"反馈内容不能为空",
                skin:"msg",
                time:1
            });
            return false
        }
        $.ajax({
            type : "POST",
            url : getRequestUrl("/user/add_feedback"),
            data:{
                content:$('#textarea').val(),
                pic_urls:imgarr.toString(),
            },
            success : function(datas) {
                console.log(datas);
                layer.open({
                    content:"提交成功,谢谢您的反馈~~",
                    skin:"msg",
                    time:1
                });
                setTimeout(function () {
                   history.go(-1)
                },2000)
            },
            error : function(err) {
            	//dealCPErrorResponse(err);
            }
        });
    }

    function getxx() {
        //user/add_feedback
        //var timev=
        $.ajax({
            type : "GET",
            url : getRequestUrl("/user/get_feedback"),
            data:{
                timestamp:new Date().getTime()
            },
            success : function(datas) {
                console.log(datas);

            },
            error : function(err) {
            	dealCPErrorResponse(err);
            }
        });
    }
</script>
</body>
</html>